import request from '@/utils/request'

// 查询数据标注列表
export function listDiseaseLabel(query) {
  return request({
    url: '/insect/diseaselabel/list',
    method: 'get',
    params: query
  })
}

// 查询数据标注详细
export function getDiseaseLabel(id) {
  return request({
    url: '/insect/diseaselabel/' + id,
    method: 'get'
  })
}

// 新增数据标注
export function addDiseaseLabel(data) {
  return request({
    url: '/insect/diseaselabel',
    method: 'post',
    data: data
  })
}

// 修改数据标注
export function updateDiseaseLabel(data) {
  return request({
    url: '/insect/diseaselabel',
    method: 'put',
    data: data
  })
}

// 删除数据标注
export function delDiseaseLabel(id) {
  return request({
    url: '/insect/diseaselabel/' + id,
    method: 'delete'
  })
}

// 导出数据标注
export function exportDiseaseLabel(query) {
  return request({
    url: '/insect/diseaselabel/export',
    method: 'get',
    params: query
  })
}

// 上传图片
export function uploadImage(data) {
  return request({
    url: '/insect/diseaselabel/uploadImage',
    method: 'post',
    data: data,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}

// 保存标注数据
export function saveAnnotations(data) {
  return request({
    url: '/insect/diseaselabel/saveAnnotations',
    method: 'post',
    data: data
  })
}

// 获取作物对应的病虫害列表
export function getDiseasesByCrop(cropName) {
  return request({
    url: '/insect/diseaselabel/getDiseasesByCrop',
    method: 'get',
    params: { cropName }
  })
}

// 获取所有作物名称列表
export function getAllCropNames() {
  return request({
    url: '/insect/cropdisease/getAllCropNames',
    method: 'get'
  })
}

// ==================== 训练相关API ====================
export function startTraining(data) {
  return request({
    url: '/insect/diseaselabel/startTraining',
    method: 'post',
    data: data,
    timeout:60000
  })
}

export function stopTraining(taskId) {
  return request({
    url: '/insect/diseaselabel/stopTraining/' + taskId,
    method: 'post'
  })
}

export function getTrainingStatus(taskId) {
  return request({
    url: '/insect/diseaselabel/trainingStatus/' + taskId,
    method: 'get'
  })
}

export function getTrainingHistory() {
  return request({
    url: '/insect/diseaselabel/trainingHistory',
    method: 'get'
  })
}

export function getTrainingLog(taskId) {
  return request({
    url: '/insect/diseaselabel/trainingLog/' + taskId,
    method: 'get'
  })
}

export function downloadModel(taskId) {
  return request({
    url: '/insect/diseaselabel/downloadModel/' + taskId,
    method: 'get'
  })
}

export function exportUserAnnotations() {
  return request({
    url: '/insect/diseaselabel/exportUserAnnotations',
    method: 'post',
    timeout:30000
  })
}

export function diagnoseSystem() {
  return request({
    url: '/insect/diseaselabel/diagnoseSystem',
    method: 'get'
  })
}

// 调试训练环境
export function debugTrainingEnvironment() {
  return request({
    url: '/insect/diseaselabel/debugTrainingEnvironment',
    method: 'get'
  })
}

// 测试简单训练
export function testSimpleTraining() {
  return request({
    url: '/insect/diseaselabel/testSimpleTraining',
    method: 'get'
  })
}

export function splitDataset() {
  return request({
    url: '/insect/diseaselabel/splitDataset',
    method: 'post',
    timeout: 120000 // 120秒，数据集分割可能较慢
  })
}

export function generateTrainingConfig(data) {
  return request({
    url: '/insect/diseaselabel/generateConfig',
    method: 'post',
    data: data,
    timeout: 30000 // 30秒
  })
}

